package org.nicocube.airain.re.proc;

import org.nicocube.airain.domain.client.character.Action;
import org.nicocube.airain.domain.client.character.Difficulty;
import org.nicocube.airain.domain.client.character.GameCharacter;
import org.nicocube.airain.domain.client.character.Possession;
import org.nicocube.airain.domain.client.character.SkillIdentifier;
import org.nicocube.airain.domain.client.character.Possession.Type;
import org.nicocube.airain.domain.client.report.HuntingActionReport;
import org.nicocube.airain.re.RuleResult;
import org.nicocube.airain.re.utils.Alea;

public class HuntingProcessor extends Processor {

	public HuntingProcessor(GameCharacter gc, Action action, Alea alea) {
		super(gc, action, alea);
	}

	@Override
	public RuleResult call() throws Exception {
		GameCharacter gc = getGc();
		
		HuntingActionReport hap = new HuntingActionReport();
		RuleResult result = new RuleResult(hap,gc);
		
		int success;
		if (gc.getPossessionByType(Type.javelin).size()>0) {
			success = getAlea().challenge(Difficulty.Fair,gc.getSkillExpertise(SkillIdentifier.Hunting));
			if (success>=0) {
				gc.addPossession(new Possession(Type.food,getAction().getGameDate()));
			}
			if (getAlea().alea(0.25)) {
				gc.getPossessionByType(Type.javelin).poll();
				hap.setJavelinBroken(true);
			}
			hap.setWithJavelin(true);
		} else {
			success = getAlea().challenge(Difficulty.Arduous,gc.getSkillExpertise(SkillIdentifier.Hunting));
			if (success>=0) {
				gc.addPossession(new Possession(Type.food,getAction().getGameDate()));
			}
			hap.setWithJavelin(false);
		}
		hap.setSuccess(success);
		return result;
	}
}
